package com.cf.balance;

import lombok.extern.slf4j.Slf4j;

import java.security.SecureRandom;
import java.util.Random;

/**
 * cf-game-RandomMachine
 * 随机器
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/3/8 13:49
 */
@Slf4j
public class RandomMachine {

    private Integer total;

    private Integer percent;

    private Random random;

    private String info;

    public RandomMachine(Integer percent, Integer total, String info) {
        this.random = new SecureRandom();
        this.total = total;
        this.percent = percent;
        this.info = info;
    }


    public boolean next() {
        int i = this.random.nextInt(total);
        if (i <= percent) {
            log.info("【{}】随机数据是【{}】在合理范围内【0-{}】，此次判定为【{true}】", info, i, percent);
            return true;
        } else {
            log.info("【{}】随机数据是【{}】在非合理范围内【0-{}】，此次判定为【false】", info, i, percent);
            return false;
        }
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public Integer getPercent() {
        return percent;
    }

    public void setPercent(Integer percent) {
        this.percent = percent;
    }

    @Override
    public String toString() {
        return "RandomMachine{" + this.percent + "/" + this.total + "}";
    }
}
